home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
datlnk.zip
/
DATELINK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-01-04
|
5KB
|
174 lines
{.I DMINUS.INC}
{$O+} {so we can overlay this unit if we decide to}
UNIT DateLink;
INTERFACE {section}
USES
TpDate,
Objects,
ObjectA,
DateObj;
TYPE
DateLinkList
= OBJECT(LinkList)
CurrentDatePtr : DateObjectPtr;
CONSTRUCTOR Init;
PROCEDURE AddDate(TheDate : Date);
PROCEDURE DeleteDate(TheDate : Date);
FUNCTION Exists(TheDate : Date) : BOOLEAN;
FUNCTION CurrentDate : Date;
FUNCTION FirstDate : Date;
FUNCTION LastDate : Date;
PROCEDURE Advance;
END;
IMPLEMENTATION {section}
{============================================================================}
CONSTRUCTOR DateLinkList.Init;
{This procedure initializes the DateLinkList.}
BEGIN {DateLinkList.Init}
CurrentDatePtr := NIL;
LinkList.Init
END; {DateLinkList.Init}
{============================================================================}
{============================================================================}
PROCEDURE DateLinkList.AddDate(TheDate : Date);
{This procedure stores TheDate in the DateLinkList. It does nothing if
TheDate already exists.}
BEGIN {DateLinkList.AddDate}
IF Exists(TheDate)
THEN EXIT; {no need to hang around here, eh?}
IF ((First = NIL)
OR (FirstDate > TheDate))
THEN
Insert(NEW(DateObjectPtr,Init(TheDate)))
ELSE
BEGIN
CurrentDatePtr := DateObjectPtr(First);
WHILE ((CurrentDate < TheDate)
AND (CurrentDate <> BadDate))
DO Advance;
{CurrentDatePtr now points to the first date coming after TheDate, or it
has a NIL value.}
IF (CurrentDate = BadDate)
THEN Append(NEW(DateObjectPtr,Init(TheDate)))
ELSE Before(NEW(DateObjectPtr,Init(TheDate)),CurrentDatePtr)
END
END; {AddDate}
{============================================================================}
{============================================================================}
PROCEDURE DateLinkList.DeleteDate(TheDate : Date);
{This procedure deletes a date from the DateLinkList. It does nothing if
the Date doesn't exist.}
BEGIN {DateLinkList.DeleteDate}
IF Exists(TheDate)
THEN
BEGIN
CurrentDatePtr := DateObjectPtr(First);
WHILE (CurrentDatePtr^.GetDate <> TheDate)
DO CurrentDatePtr := DateObjectPtr(CurrentDatePtr^.Next);
{CurrentDatePtr now points to the proper date.}
Remove(CurrentDatePtr);
DISPOSE(CurrentDatePtr,Done);
CurrentDatePtr := NIL
END
END; {DateLinkList.DeleteDate}
{============================================================================}
{============================================================================}
FUNCTION DateLinkList.Exists(TheDate : Date) : BOOLEAN;
{This function determines if the date is on the DateLinkList.}
VAR
TempBoolean : BOOLEAN;
BEGIN {DateLinkList.Exists}
IF ((TheDate = BadDate) OR (FirstDate = BadDate))
THEN
Exists := FALSE
ELSE
BEGIN
TempBoolean := FALSE;
REPEAT
IF (CurrentDatePtr^.GetDate = TheDate)
THEN TempBoolean := TRUE;
{ELSE leave TempBoolean alone}
CurrentDatePtr := DateObjectPtr(Next(CurrentDatePtr))
UNTIL (CurrentDatePtr = NIL);
Exists := TempBoolean
END
END; {DateLinkList.Exists}
{============================================================================}
{============================================================================}
FUNCTION DateLinkList.CurrentDate : Date;
{This function returns the current date in the DateLinkList.}
BEGIN {DateLinkList.CurrentDate}
IF (CurrentDatePtr = NIL)
THEN CurrentDate := BadDate
ELSE CurrentDate := CurrentDatePtr^.GetDate
END; {DateLinkList.CurrentDate}
{============================================================================}
{============================================================================}
FUNCTION DateLinkList.FirstDate : Date;
{This function simply returns the first date in the LinkList.}
BEGIN {DateLinkList.FirstDate}
CurrentDatePtr := DateObjectPtr(First);
IF (CurrentDatePtr = NIL)
THEN FirstDate := BadDate
ELSE FirstDate := CurrentDatePtr^.GetDate
END; {DateLinkList.FirstDate}
{============================================================================}
{============================================================================}
FUNCTION DateLinkList.LastDate : Date;
{This function simply returns the last date in the LinkList.}
BEGIN {DateLinkList.LastDate}
CurrentDatePtr := DateObjectPtr(Last);
IF (CurrentDatePtr = NIL)
THEN LastDate := BadDate
ELSE LastDate := CurrentDatePtr^.GetDate
END; {DateLinkList.LastDate}
{============================================================================}
{============================================================================}
PROCEDURE DateLinkList.Advance;
{This procedure simply moves to the next date in the DateLinkList.}
BEGIN {DateLinkList.NextDate}
CurrentDatePtr := DateObjectPtr(Next(CurrentDatePtr))
END; {NextDate}
{============================================================================}
END. {DateLink}